﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommTestNFW.ImageCode
{
    public class LabelConfig
    {
        public static string BasePath = "D:/test/print-img";

        public static int PageWidth = 2030;
        public static int PageHeight = 1400;

        //双排标识   在页面四角打印彩边
        public static bool DoublePrintFlag = true;

        public static float RealWidth = 10;//mm
        public static float RealHeight = 20;
        public static float RealGap = 2;
        //页面内距
        public static string RealPagePadding = "5,7,5.5,7";
        //标签内距, 需要和字体大小同时调整, 否则字不居中, 且可能越界
        public static float RealLabelPadding = .5F;
         
        public static int RowsCount = 9;
        public static int ColsCount = 24;

    }

    /// <summary>
    /// 内距
    /// 上右下左
    /// </summary>
    public class Padding : ICloneable
    {
        public float Top { get; set; }
        public float Right { get; set; }
        public float Bottom { get; set; }
        public float Left { get; set; }

        public float Horizontal
        {
            get
            {
                return Left + Right;
            }
        }
        public float Vertical
        {
            get
            {
                return Top + Bottom;
            }
        }

        public Padding()
        {
        }

        public Padding(params float[] padding)
        {
            var len = padding.Length;
            var fullPadding = new float[4];
            for (int i = 0; i < len; i++)
                fullPadding[i] = padding[i];

            if (len == 1)
            {
                fullPadding[1] = fullPadding[0];
                fullPadding[2] = fullPadding[0];
                fullPadding[3] = fullPadding[0];
            }
            else if (len == 2)
            {
                fullPadding[1] = fullPadding[0];

                fullPadding[2] = fullPadding[2];
                fullPadding[3] = fullPadding[2];
            }
            else if (len == 3)
            {
                fullPadding[3] = fullPadding[2];
            }

            SetPadding(fullPadding[0], fullPadding[1], fullPadding[2], fullPadding[3]);
        }

        public Padding SetPadding(float top, float right, float bottom, float left)
        {
            Top = top;
            Right = right;
            Bottom = bottom;
            Left = left;
            return this;
        }

        public Padding Boost(float factor)
        {

            Top *= factor;
            Right *= factor;
            Bottom *= factor;
            Left *= factor;
            return this;
        }

        public object Clone()
        {
            return MemberwiseClone();
        }

        public static implicit operator Padding(float padding)
        {
            return new Padding(padding);
        }

        public static implicit operator Padding(string padding)
        {
            if (string.IsNullOrWhiteSpace(padding))
                return new Padding(0);

            var paddings = padding.Split(',')
                .AsEnumerable()
                .Select(s => float.Parse(s))
                .ToArray();
            return new Padding(paddings);
        }
    }
}
